# Definition for singly-linked list.
from typing import Optional


class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution:
    def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:
        l3 = l1
        if not l1:
            return l2
        if not l2:
            return l1
        while not l1 and not l2:
            l1.val = l1.val + l2.val
            l1 = l1.next
            l2 = l2.next
        l3 = l1 if l1 is not None else l2

        l1.next = l3
        return l3



